package com.cn.RedisThread;

import com.cn.entity.Works_Comment;
import com.cn.mapper.Works.WorksMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
@Component("Redis_Set_WorksComments")
public class Redis_Set_WorksComment extends Thread{
    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    WorksMapper worksMapper;
    Redis_Set_WorksComment(){

    }

    @Override
    public void run() {
        List<Works_Comment> works_commentList;
        works_commentList=worksMapper.showCommentByWorksId();
        System.out.println("Redis缓存线程启动成功");


        for(Works_Comment works_comment : works_commentList){
            String key="works_comment:"+works_comment.getWorksId()*2+works_comment.getCommentId();
            redisTemplate.opsForValue().setIfAbsent(key,works_comment);
        }
    }
}
